﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace ThreadFramework
{
    public class YLTime
    {
        private AutoResetEvent singalDone = new AutoResetEvent(false);

        public void Init(object timeSec)
        {
            int Sec = (int)timeSec;
            singalDone.Reset();
            bool result = false;
            int i = 0;
            for (; i < Sec; i++)
            {
                result = singalDone.WaitOne(1000);
                //刷新界面--刷新信号
#if DEBUG
                Console.WriteLine(i.ToString());
#endif
                if (result)
                {
                    break;
                }
            }
            if (result && i < Sec)
            {
                //在等待时间段，完成指令
#if DEBUG
                Console.WriteLine("在等待时间段，完成指令");
#endif
            }
            else//发出无效信号
            {
#if DEBUG
                Console.WriteLine("发出无效信号");
#endif
            }
        }

        public void SendOpenSingal() 
        {
            singalDone.Set();
        }
    }
}
